package com.example.backend_422.controller;


import com.example.backend_422.common.Result;
import com.example.backend_422.service.impl.RentServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xwyzsn
 * @since 2023-04-22
 */
@RestController // @RestController = @Controller + @ResponseBody
@RequestMapping("/rent") // URL地址映射,这里的地址是http://localhost:8085/rent
@CrossOrigin(origins = "*",maxAge = 3600) // 允许跨域
public class RentController {


    @Autowired
    private RentServiceImpl rentService; // 注入Service
    @GetMapping("getByUserId")// URL地址映射，获取用户的订单
    // 接受前端传来的参数，参数名为userId，类型为Integer
    public Result getRentByUserId(@RequestParam("userId") Integer userId){
        // 调用Service层的方法，具体实现在ServiceImpl层,说明也在ServiceImpl层
        return rentService.getRentByUserId(userId);
    }
    @GetMapping("getByLandlordId")// URL地址映射，获取房东的订单
    // 接受前端传来的参数，参数名为userId，类型为Integer
    public Result getByLandlordId(@RequestParam("landlordId") Integer landlordId){
        // 调用Service层的方法，具体实现在ServiceImpl层,说明也在ServiceImpl层
        return rentService.getByLandlordId(landlordId);
    }
    @PostMapping("setStatus")// URL地址映射，设置订单状态
    // 接受前端传来的参数，参数名为userId，类型为Integer,参数名为status，类型为String,参数名为rentId，类型为Integer
    public Result setRentStatus(@RequestParam("houseId") Integer houseId,@RequestParam("status") String status,
                                @RequestParam("rentId") Integer rentId){
        return rentService.setRentStatus(houseId,status,rentId);
    }

    @GetMapping("getquit") // URL地址映射，获取退房订单
    // 接受前端传来的参数，参数名为landlordId，类型为Integer
    public Result getQuitOrder(@RequestParam("landlordId") Integer landlordId){
        return rentService.getQuitOrder(landlordId);
    }

    @PostMapping("confirmQuit")// URL地址映射，确认退房
    // 接受前端传来的参数，参数名为userId，类型为Integer,参数名为status，类型为String,参数名为rentId，类型为Integer
    public Result confirmQuit(@RequestParam("status") String status,
                              @RequestParam("rentId") Integer rentId,@RequestParam("endTime") String endTime,
                              @RequestParam(value = "houseId",required = false) Integer houseId){
        return rentService.confirmQuit(endTime,status,rentId,houseId);
}}
